﻿using Loaf.Beans;
using Loaf.Views;
using Prism.Commands;
using Prism.Ioc;
using Prism.Regions;

namespace Loaf.ViewModels
{
    public class MainWindowModel
    {
        private IContainerProvider Container;
        private readonly IRegionManager _regionManager;
        public Context Context { get; set; }
        public DelegateCommand<string> NavigationCommand { get; set; }


        public MainWindowModel(Context context, IRegionManager regionManager, IContainerProvider container)
        {
            _regionManager = regionManager;
            Container = container;

            Context = context;

            NavigationCommand = new DelegateCommand<string>(NavigationAction);

        }

        public void OnLoaded()
        {
            if (Context.BookSetting.LastBook != null)
            {
                Context.ReaderWindow = Container.Resolve<ReaderWindow>();
            }
            else
            {
                _regionManager.Regions["MainRegion"].RequestNavigate("HomeView");
            }
        }

        public void NavigationAction(string name)
        {
            _regionManager.Regions["MainRegion"].RequestNavigate(name);
        }
    }
}
